﻿using LitJson;
using LNet;
using OestsCommon.Model;
using OestsDataBase;
using OestsServer.Net;
using System.Collections.Generic;

namespace OestsServer.Handlers.UnityHandlers
{

    /*
     *  考试 参数:paperId  返回一个 paper
     */
    public class GetOperateExamListHandler : HandlerBase<UnityClientChannel>
    {
        /// <summary>
        ///unity端获取当前项目的操作考试列表
        /// </summary>
        /// <param name="client"></param>
        /// <param name="packet"></param>
        public override PacketKey PKey
        {
            get
            {
                return PacketKey.GetOperateExamList;
            }
        }

        public override void Execute(UnityClientChannel client, Request packet)
        {
            base.Execute(client, packet);
            int projectId = int.Parse(packet.DataStr);

            List<ExamModel> data = ExamDAL.GetOperateExamsByStudent(client.User.DBid, projectId);

            if (data == null || data.Count == 0)
            {
                ResponsePacket.ReturnCode = ReturnCode.Fail;
                ResponsePacket.RetrunMessage = "当前无操作考试，请联系管理员！";
            }
            else
                ResponsePacket.ReturnCode = ReturnCode.Success;
            ResponsePacket.DataObject = data;
            client.Send(ResponsePacket);

        }
    }
    public class GetTaskListHandler : HandlerBase<UnityClientChannel>
    {
        /// <summary>
        ///unity端获取当前项目的操作考试列表
        /// </summary>
        /// <param name="client"></param>
        /// <param name="packet"></param>
        public override PacketKey PKey
        {
            get
            {
                return PacketKey.GetTaskList;
            }
        }


        public override void Execute(UnityClientChannel client, Request packet)
        {
            base.Execute(client, packet);
            // int paperId = int.Parse(packet.DataStr);
            DP<int, int> data = JsonMapper.ToObject<DP<int, int>>(packet.DataStr);

            List<TaskModel> listTask = PaperDAL.GetTasksInPaper(data.Value1, data.Value2, client.User.DBid);
            ResponsePacket.DataObject = listTask;
            client.Send(ResponsePacket);

        }
    }



}
